<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="收藏关注" title-size="36" title-color="#333"></u-navbar>

        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            font-size="32"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            bar-width="50"
            active-color="#10A28F"
            swiper-width="750rpx"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>

      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item v-for="(sitem, sindex) in tabsList" class="swiperItem" :key="sindex">
          <z-paging
            ref="paging"
            v-model="itemList[sindex]"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-if="sindex == 0"
                v-for="(item, index1) in itemList[sindex]"
                :key="index1"
              >
                <view
                  class="dis-flex flex-y-center"
                  @click="routeTo('/shops/goods-detail?goodsId=' + item.spuId)"
                  v-if="item.spu"
                  style="padding: 10rpx 0"
                >
                  <view class="">
                    <u-image
                      :src="item.spu.picUrl"
                      width="150rpx"
                      height="150rpx"
                      border-radius="10"
                    ></u-image>
                  </view>
                  <view
                    class="dis-flex flex-y-between"
                    style="margin-left: 20rpx; flex-flow: column; height: 150rpx"
                  >
                    <view class="title">{{ item.spu.name }}</view>
                    <view class="price" style="color: #fa453c; font-size: 32rpx"
                      ><text style="font-size: 26rpx">¥</text
                      >{{ (item.spu.price * 0.01).toFixed(2) }}
                    </view>
                  </view>
                  <view class="deleteBt" @click.stop.prevent="cancelGoodsFollow(item)">取消</view>
                </view>
              </view>

              <view
                class="itemView itemView-3"
                @click="toStoreDetail(item)"
                v-if="sindex == 1"
                v-for="(item, index1) in itemList[sindex]"
                :key="index1"
              >
                <view style="border: 1rpx solid #f3f4f6; border-radius: 10rpx">
                  <u-image
                    :src="item.shop.logo"
                    width="160rpx"
                    height="160rpx"
                    border-radius="10"
                  ></u-image>
                </view>
                <view class="shop-info">
                  <view class="shop-name">{{ item.shop.name }}</view>
                  <view class="shop-star dis-flex flex-y-center">
                    <!-- <u-image style="margin-bottom: 4rpx;" src="@/static/1.png" width="28rpx"
											height="28rpx"></u-image>
										<text class="goods-star">{{item.shop.score}}分</text> -->
                    <text class="goods-star">{{ item.shop.businessHours }}</text>
                  </view>
                  <view style="width: 100%; margin-bottom: 10rpx" class="dis-flex flex-y-center">
                    <!-- <view class="sale-item" style="margin-right: 50rpx;">
											<text>起送价¥ 23</text>
										</view>
										<view class="sale-item">
											<text>人均¥18</text>
										</view> -->
                    <view class="sale-item" style="margin-right: 50rpx">
                      <text>{{ item.shop.detailAddress }}</text>
                      <text class="deleteBt" @click.stop.prevent="cancelShopFollow(item)"
                        >取消</text
                      >
                    </view>
                  </view>
                </view>
              </view>

              <view
                class="itemView itemView-1"
                v-if="sindex == 2"
                v-for="(item, index1) in itemList[sindex]"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="company-detail dis-flex flex-y-between flex-y-center">
                  <view class="com-l dis-flex flex-y-center">
                    <u-image
                      class="com-avarar"
                      :src="item.avatar"
                      width="90rpx"
                      height="90rpx"
                    ></u-image>
                    <view class="com-d">
                      <view class="com-t">{{ item.company }}</view>
                      <view class="com-c">
                        <text class="eq">{{ item.label }}</text>
                        <text class="eq">{{ item.guimo }}</text>
                        <text class="eq">{{ item.industry }}</text>
                      </view>
                    </view>
                  </view>
                  <u-image
                    class="more"
                    src="@/static/more.png"
                    width="16rpx"
                    height="28rpx"
                  ></u-image>
                </view>
                <view class="zw">
                  <text>{{ item.zw }}</text>
                  <text style="margin: 0 10rpx">/</text>
                  <text>{{ item.count }}</text>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      show: false,
      current: 0,
      scurrent: 0,
      resStatus: '',
      tabsList: [
        {
          name: '商品',
          status: '',
          commentStatus: ''
        },
        {
          name: '店铺',
          status: 0,
          commentStatus: ''
        },
        {
          name: '信息',
          status: 0,
          commentStatus: ''
        },
        {
          name: '关注',
          status: 0,
          commentStatus: ''
        }
      ],
      itemList: [[], [], [], []],
      order_id: ''
    }
  },
  onLoad(res) {
    this.current = Number(res.index) ? Number(res.index) : 0
    this.scurrent = Number(res.index) ? Number(res.index) : 0
  },

  onShow() {
    let self = this
    this.queryList()
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    routeTo(url) {
      uni.navigateTo({
        url
      })
    },
    animationfinish(e) {
      this.current = e.detail.current
      this.scurrent = e.detail.current
      this.$refs.uTabs.setFinishCurrent(e.detail.current)
      if (this.itemList[this.current].length == 0) {
        this.queryList()
      }
    },
    queryList(pageNo = 1, pageSize = 10) {
      let url = ''
      if (this.scurrent == 0) {
        url = '/app-api/product/favorite/page'
      } else if (this.scurrent == 1) {
        url = '/app-api/shop/favorite/page'
      }
      this.$u
        .get(url, {
          pageNo,
          pageSize
        })
        .then((res) => {
          let dynamicPaging = this.scurrent > 0 ? 'paging' + this.scurrent : 'paging'
          this.$refs.paging[this.scurrent].complete(res.data.list)
        })
    },
    toStoreDetail(item) {
      if (item.type == 'food') {
        uni.navigateTo({
          url:
            '/other/merchant-center/merchant-center?id=' +
            item.shop.id +
            '&shop=' +
            JSON.stringify(item.shop)
        })
      } else if (item.type == 'hotel') {
        uni.navigateTo({
          url:
            '/other/merchant-center/merchant-center-hotel?id=' +
            item.shop.id +
            '&shop=' +
            JSON.stringify(item.shop)
        })
      } else if (item.type == 'entertainment') {
        uni.navigateTo({
          url:
            '/other/merchant-center/merchant-center-yule?id=' +
            item.shop.id +
            '&shop=' +
            JSON.stringify(item.shop)
        })
      } else {
        uni.navigateTo({
          url: '/other/merchant-center/merchant-center?id=' + item.shop.id
        })
      }
    },
    cancelGoodsFollow(item) {
      this.$u
        .post('/app-api/product/favorite/toggle', {
          spuId: item.spuId
        })
        .then((res) => {
          if (res.code === 0) {
            this.$u.toast('已取消收藏')
            this.queryList()
          } else {
            this.$u.toast(res.msg)
          }
        })
    },
    cancelShopFollow(item) {
      uni.$u
        .post('/app-api/shop/favorite/toggle', {
          shopId: item.shopId
        })
        .then((res) => {
          if (res.code === 0) {
            this.$u.toast('已取消收藏')
            this.queryList()
          } else {
            this.$u.toast(res.msg)
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
page {
  height: 100%;
  background: #f0f1f2;
}

.goodsItemView {
  padding: 0 20rpx;
}

.deleteBt {
  width: 120rpx;
  height: 50rpx;
  border-radius: 25rpx;
  border: 1px solid #fa453c;
  position: absolute;
  right: 20rpx;
  bottom: 20rpx;
  font-size: 26rpx;
  color: #fa453c;
  text-align: center;
  line-height: 50rpx;
}

.itemView {
  // height: 300rpx;
  background: #ffffff;
  border-radius: 10rpx;
  padding: 10rpx 20rpx;
  margin-bottom: 20rpx;
  display: flex;
  flex-flow: column;
  justify-content: space-around;
  position: relative;

  .top {
    // margin-bottom: 22rpx;
    .title {
      font-weight: 600;
      font-size: 34rpx;
      color: #333333;
    }

    .price {
      font-weight: 600;
      font-size: 34rpx;
      color: #fa453c;
    }
  }

  .yaoqiu {
    // margin-bottom: 22rpx;
    .bq {
      background: #f0f0f0;
      border-radius: 5rpx;
      padding: 8rpx;
      font-size: 20rpx;
      color: #666666;
      margin-right: 10rpx;
    }
  }

  .company {
    font-size: 28rpx;
    color: #333333;

    // margin-bottom: 22rpx;
    .name {
      margin-right: 40rpx;
    }
  }

  .bottom {
    .user {
      .label {
        margin-left: 10rpx;
        font-size: 28rpx;
      }
    }

    .add {
      font-size: 26rpx;
      color: #999999;

      .detail {
        margin-left: 10rpx;
      }
    }
  }
}

.itemView-1 {
  // height: 180rpx;
  .company-detail {
    .com-avarar {
      margin-right: 20rpx;
      border-radius: 10rpx;
    }

    .com-d {
      height: 90rpx;
      display: flex;
      flex-flow: column;
      justify-content: space-between;
      padding: 4rpx 0;

      .com-t {
        font-size: 30rpx;
        font-weight: 600;
      }

      .com-c {
        color: #999999;
        font-size: 24rpx;

        .eq {
          border-right: 1rpx solid #999999;
          padding-right: 10rpx;
          margin-right: 14rpx;
        }

        .eq:last-child {
          border: none;
        }
      }
    }
  }

  .zw {
    margin-left: 110rpx;
    color: #666666;
    font-size: 26rpx;
  }
}

.itemView-3 {
  display: flex;
  flex-flow: row;
  align-items: center;
  justify-content: flex-start;
  height: auto;
  padding: 20rpx;

  .shop-info {
    flex: 1;
    margin-left: 20rpx;
    height: 160rpx;
    display: flex;
    flex-flow: column;
    justify-content: space-between;

    .goods-star {
      font-size: 30rpx;
      color: #333333;
      margin-left: 8rpx;
    }

    .sale-item {
      font-size: 24rpx;
      color: #666666;
      /* margin-right: 50rpx; */
    }
  }
}
</style>
